from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-09 14:06:18.049785
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 09, Feb, 2022
Time: 14:06:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.0413
Nobs: 562.000 HQIC: -48.4641
Log likelihood: 6607.52 FPE: 6.83452e-22
AIC: -48.7349 Det(Omega_mle): 5.83137e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.351132 0.069097 5.082 0.000
L1.Burgenland 0.106203 0.042000 2.529 0.011
L1.Kärnten -0.110639 0.021820 -5.071 0.000
L1.Niederösterreich 0.193451 0.087616 2.208 0.027
L1.Oberösterreich 0.130999 0.086616 1.512 0.130
L1.Salzburg 0.254823 0.044397 5.740 0.000
L1.Steiermark 0.035155 0.058534 0.601 0.548
L1.Tirol 0.099514 0.047242 2.106 0.035
L1.Vorarlberg -0.071023 0.041774 -1.700 0.089
L1.Wien 0.017775 0.077076 0.231 0.818
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055923 0.149539 0.374 0.708
L1.Burgenland -0.040991 0.090894 -0.451 0.652
L1.Kärnten 0.041191 0.047222 0.872 0.383
L1.Niederösterreich -0.198595 0.189615 -1.047 0.295
L1.Oberösterreich 0.458570 0.187452 2.446 0.014
L1.Salzburg 0.282033 0.096083 2.935 0.003
L1.Steiermark 0.113352 0.126679 0.895 0.371
L1.Tirol 0.304266 0.102240 2.976 0.003
L1.Vorarlberg 0.022946 0.090406 0.254 0.800
L1.Wien -0.028835 0.166807 -0.173 0.863
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.195891 0.035282 5.552 0.000
L1.Burgenland 0.089902 0.021445 4.192 0.000
L1.Kärnten -0.007443 0.011141 -0.668 0.504
L1.Niederösterreich 0.235603 0.044737 5.266 0.000
L1.Oberösterreich 0.165519 0.044227 3.742 0.000
L1.Salzburg 0.040029 0.022669 1.766 0.077
L1.Steiermark 0.026622 0.029888 0.891 0.373
L1.Tirol 0.082458 0.024122 3.418 0.001
L1.Vorarlberg 0.054850 0.021330 2.571 0.010
L1.Wien 0.118314 0.039356 3.006 0.003
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120724 0.035315 3.418 0.001
L1.Burgenland 0.043374 0.021466 2.021 0.043
L1.Kärnten -0.013346 0.011152 -1.197 0.231
L1.Niederösterreich 0.170498 0.044780 3.807 0.000
L1.Oberösterreich 0.335158 0.044269 7.571 0.000
L1.Salzburg 0.099764 0.022691 4.397 0.000
L1.Steiermark 0.110587 0.029916 3.697 0.000
L1.Tirol 0.090362 0.024145 3.742 0.000
L1.Vorarlberg 0.060614 0.021350 2.839 0.005
L1.Wien -0.017884 0.039393 -0.454 0.650
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.125611 0.066501 1.889 0.059
L1.Burgenland -0.048448 0.040421 -1.199 0.231
L1.Kärnten -0.045478 0.021000 -2.166 0.030
L1.Niederösterreich 0.140118 0.084323 1.662 0.097
L1.Oberösterreich 0.163213 0.083361 1.958 0.050
L1.Salzburg 0.284722 0.042729 6.663 0.000
L1.Steiermark 0.057507 0.056335 1.021 0.307
L1.Tirol 0.156446 0.045467 3.441 0.001
L1.Vorarlberg 0.094851 0.040204 2.359 0.018
L1.Wien 0.074681 0.074180 1.007 0.314
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080700 0.051910 1.555 0.120
L1.Burgenland 0.024678 0.031553 0.782 0.434
L1.Kärnten 0.053289 0.016392 3.251 0.001
L1.Niederösterreich 0.191140 0.065822 2.904 0.004
L1.Oberösterreich 0.328495 0.065072 5.048 0.000
L1.Salzburg 0.033584 0.033354 1.007 0.314
L1.Steiermark 0.005459 0.043975 0.124 0.901
L1.Tirol 0.120350 0.035491 3.391 0.001
L1.Vorarlberg 0.066168 0.031383 2.108 0.035
L1.Wien 0.098063 0.057905 1.694 0.090
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172490 0.062692 2.751 0.006
L1.Burgenland 0.003081 0.038106 0.081 0.936
L1.Kärnten -0.065754 0.019797 -3.321 0.001
L1.Niederösterreich -0.110865 0.079494 -1.395 0.163
L1.Oberösterreich 0.212295 0.078587 2.701 0.007
L1.Salzburg 0.053459 0.040281 1.327 0.184
L1.Steiermark 0.249090 0.053109 4.690 0.000
L1.Tirol 0.499080 0.042863 11.644 0.000
L1.Vorarlberg 0.065721 0.037902 1.734 0.083
L1.Wien -0.075240 0.069932 -1.076 0.282
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.157801 0.069367 2.275 0.023
L1.Burgenland -0.005274 0.042163 -0.125 0.900
L1.Kärnten 0.061838 0.021905 2.823 0.005
L1.Niederösterreich 0.176781 0.087957 2.010 0.044
L1.Oberösterreich -0.066266 0.086954 -0.762 0.446
L1.Salzburg 0.205867 0.044570 4.619 0.000
L1.Steiermark 0.139462 0.058763 2.373 0.018
L1.Tirol 0.057383 0.047426 1.210 0.226
L1.Vorarlberg 0.143570 0.041937 3.424 0.001
L1.Wien 0.132115 0.077377 1.707 0.088
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393861 0.040711 9.674 0.000
L1.Burgenland -0.003339 0.024746 -0.135 0.893
L1.Kärnten -0.021228 0.012856 -1.651 0.099
L1.Niederösterreich 0.199542 0.051622 3.865 0.000
L1.Oberösterreich 0.231801 0.051033 4.542 0.000
L1.Salzburg 0.036370 0.026158 1.390 0.164
L1.Steiermark -0.017347 0.034488 -0.503 0.615
L1.Tirol 0.090693 0.027834 3.258 0.001
L1.Vorarlberg 0.052061 0.024613 2.115 0.034
L1.Wien 0.040629 0.045412 0.895 0.371
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.035071 0.105429 0.168825 0.134043 0.095932 0.080856 0.030349 0.212348
Kärnten 0.035071 1.000000 -0.025802 0.132437 0.046716 0.085571 0.444116 -0.068622 0.090583
Niederösterreich 0.105429 -0.025802 1.000000 0.311561 0.124656 0.269995 0.065611 0.156523 0.284407
Oberösterreich 0.168825 0.132437 0.311561 1.000000 0.214638 0.293546 0.168164 0.134267 0.235643
Salzburg 0.134043 0.046716 0.124656 0.214638 1.000000 0.124857 0.090799 0.103310 0.128204
Steiermark 0.095932 0.085571 0.269995 0.293546 0.124857 1.000000 0.134209 0.105808 0.031482
Tirol 0.080856 0.444116 0.065611 0.168164 0.090799 0.134209 1.000000 0.063296 0.151811
Vorarlberg 0.030349 -0.068622 0.156523 0.134267 0.103310 0.105808 0.063296 1.000000 -0.003282
Wien 0.212348 0.090583 0.284407 0.235643 0.128204 0.031482 0.151811 -0.003282 1.000000